#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

int main()
{
    pid_t pid = 0;

    printf("hzftest begin main\n");
    pid = fork();

    if(pid < 0)
    {
        printf("hzftest fork error!\n");
        return -1;
    }
    else if(pid == 0)
    {
        printf("hzftest I am the child process, my pid is %d\n", getpid());
		sleep(3);
        printf("hzftest I am the child process, my pid is %d, sleep 3s\n", getpid());
    }
    else
    {
		int status = 0;
		pid = wait(&status);
		if(WIFEXITED(status))
		{
			printf("hzftest The child process %d exit ok!, status=%d\n", pid, WEXITSTATUS(status));
		}
		else
		{
			printf("hzftest The child process %d exit bad!\n", pid);
		}
        printf("hzftest I am the parent process, my pid is %d, wait pid=%d, wait status=%d\n", getpid(), pid, status);
    }

    printf("hzftest end main\n");
    return 0;
}
